Page({
    data: {
        currentView: 0,
    },

    onLoad() {
        const vtabs = [
            "热搜推荐",
            "手机数码",
            "家用电器",
            "生鲜果蔬",
            "酒水饮料",
            "生活美食",
            "美妆护肤",
            "个护清洁",
            "女装内衣",
            "男装内衣",
            "鞋靴箱包",
            "运动户外",
            "生活充值",
            "母婴童装",
            "玩具乐器",
            "家居建材",
            "计生情趣",
            "医药保健",
            "时尚钟表",
            "珠宝饰品",
            "礼品鲜花",
            "图书音像",
            "房产",
            "电脑办公",
        ];
        this.setData({ vtabs });
        this.setData({ activeId: 0 })
    },

    onTap() {
        this.setData({
            currentView: this.data.currentView + 1,
        });
    },

    clickItem(e) {
        this.setData({
            activeId: e.currentTarget.dataset.id,
            currentView: e.currentTarget.dataset.id,
        });
    },

    handleContentScroll(e) {
        console.log(e.detail.scrollTop);
        console.log(this.data._heightRecords);
        var _heightRecords = this.data._heightRecords
        if (_heightRecords.length === 0) return
        var length = this.data.vtabs.length
        var scrollTop = e.detail.scrollTop

        if (scrollTop < 156) {
            this.setData({
                activeId: 0
            })
        }
        if (scrollTop >= _heightRecords[0]) {
            for (var i = 1; i < length; i++) {
                if (scrollTop >= _heightRecords[i - 1] && scrollTop < _heightRecords[i]) {
                    this.setData({
                        activeId: i
                    })
                }
            }

        }



    },

    getDataFromChild(e) {
        this.setData({
            _heightRecords: e.detail
        })
    }
});